@@ -22,7 +22,6 @@ class ApplicationController < ActionController::Base |
||
| 22 | 22 |
return unless current_user |
| 23 | 23 |
twitter_oauth_check |
| 24 | 24 |
basecamp_auth_check |
| 25 |
- tumblr_oauth_check |
|
| 26 | 25 |
end |
| 27 | 26 |
|
| 28 | 27 |
private |
@@ -41,13 +40,4 @@ class ApplicationController < ActionController::Base |
||
| 41 | 40 |
@basecamp_agent = current_user.agents.where(type: 'Agents::BasecampAgent').first |
| 42 | 41 |
end |
| 43 | 42 |
end |
| 44 |
- |
|
| 45 |
- def tumblr_oauth_check |
|
| 46 |
- if ENV['TUMBLR_OAUTH_KEY'].blank? || ENV['TUMBLR_OAUTH_SECRET'].blank? |
|
| 47 |
- if @tumblr_agent = current_user.agents.where("type like 'Agents::Tumblr%'").first
|
|
| 48 |
- @tumblr_oauth_key = @tumblr_agent.options['consumer_key'].presence || @tumblr_agent.credential('tumblr_consumer_key')
|
|
| 49 |
- @tumblr_oauth_secret = @tumblr_agent.options['consumer_secret'].presence || @tumblr_agent.credential('tumblr_consumer_secret')
|
|
| 50 |
- end |
|
| 51 |
- end |
|
| 52 |
- end |
|
| 53 | 43 |
end |
@@ -101,7 +101,6 @@ module Agents |
||
| 101 | 101 |
options = interpolated(event)['options'] |
| 102 | 102 |
begin |
| 103 | 103 |
post = publish_post(blog_name, post_type, options) |
| 104 |
- puts "[POST] "+JSON.pretty_generate(post) |
|
| 105 | 104 |
create_event :payload => {
|
| 106 | 105 |
'success' => true, |
| 107 | 106 |
'published_post' => "["+blog_name+"] "+post_type, |
@@ -113,10 +112,7 @@ module Agents |
||
| 113 | 112 |
end |
| 114 | 113 |
end |
| 115 | 114 |
|
| 116 |
- def publish_post(blog_name, post_type, options) |
|
| 117 |
- puts "[BLOG NAME] "+blog_name |
|
| 118 |
- puts "[POST_TYPE] "+post_type |
|
| 119 |
- |
|
| 115 |
+ def publish_post(blog_name, post_type, options) |
|
| 120 | 116 |
options_obj = {
|
| 121 | 117 |
:state => options['state'], |
| 122 | 118 |
:tags => options['tags'], |
@@ -0,0 +1,38 @@ |
||
| 1 |
+require 'spec_helper' |
|
| 2 |
+ |
|
| 3 |
+describe Agents::TumblrPublishAgent do |
|
| 4 |
+ before do |
|
| 5 |
+ @opts = {
|
|
| 6 |
+ :blog_name => "huginnbot.tumblr.com", |
|
| 7 |
+ :post_type => "text", |
|
| 8 |
+ :expected_update_period_in_days => "2", |
|
| 9 |
+ :options => {
|
|
| 10 |
+ :title => "{{title}}",
|
|
| 11 |
+ :body => "{{body}}",
|
|
| 12 |
+ }, |
|
| 13 |
+ } |
|
| 14 |
+ |
|
| 15 |
+ @checker = Agents::TumblrPublishAgent.new(:name => "HuginnBot", :options => @opts) |
|
| 16 |
+ @checker.service = services(:generic) |
|
| 17 |
+ @checker.user = users(:bob) |
|
| 18 |
+ @checker.save! |
|
| 19 |
+ |
|
| 20 |
+ @event = Event.new |
|
| 21 |
+ @event.agent = agents(:bob_weather_agent) |
|
| 22 |
+ @event.payload = { :title => "Gonna rain...", :body => 'San Francisco is gonna get wet' }
|
|
| 23 |
+ @event.save! |
|
| 24 |
+ |
|
| 25 |
+ stub.any_instance_of(Agents::TumblrPublishAgent).tumblr {
|
|
| 26 |
+ stub!.text(anything, anything) { { "id" => "5" } }
|
|
| 27 |
+ } |
|
| 28 |
+ end |
|
| 29 |
+ |
|
| 30 |
+ describe '#receive' do |
|
| 31 |
+ it 'should publish any payload it receives' do |
|
| 32 |
+ Agents::TumblrPublishAgent.async_receive(@checker.id, [@event.id]) |
|
| 33 |
+ @checker.events.count.should eq(1) |
|
| 34 |
+ @checker.events.first.payload['post_id'].should eq('5')
|
|
| 35 |
+ @checker.events.first.payload['published_post'].should eq('[huginnbot.tumblr.com] text')
|
|
| 36 |
+ end |
|
| 37 |
+ end |
|
| 38 |
+end |